package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class BaseDao {
	private Connection connection;
	private ResultSet rs;
	private PreparedStatement ps;

	public Connection getConnection() throws SQLException,
			ClassNotFoundException {
		if (connection == null || connection.isClosed()) {
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/ebook";
			connection = DriverManager.getConnection(url, "root", "4682135");
		}
		return connection;
	}

	// closeAll
	public void closeAll(Connection connection, ResultSet rs,
			PreparedStatement ps) {
		try {
			if (rs != null) {
				rs.close();
			}
			if (ps != null) {
				ps.close();
			}
			if (connection != null) {
				connection.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}
	public Integer sOruOrd(String sql,Object... obj){
		int num = 0;
		try {
			connection = this.getConnection();
			ps = connection.prepareStatement(sql);





		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}finally {
			this.closeAll(connection, rs, ps);
		
		}
		return num;
	}
}
